package com.yuzhitong.shapi.presenter;

import com.yuzhitong.shapi.base.BasePresenter;
import com.yuzhitong.shapi.base.Contents;
import com.yuzhitong.shapi.base.net.BaseListBean;
import com.yuzhitong.shapi.bean.MovieBean;
import com.yuzhitong.shapi.contract.MovieListContract;
import com.yuzhitong.shapi.model.MovieListModel;
import com.yuzhitong.shapi.net.MyObserver;
import com.yuzhitong.shapi.net.RxScheduler;

import java.util.Map;

import io.reactivex.rxjava3.annotations.NonNull;

/**
 * Created by Brsya
 * CreateDate: 2022/5/8  15:52
 * Description:
 * 影视列表
 */
public class MovieListPresenter extends BasePresenter<MovieListContract.View> implements MovieListContract.Presenter {
    private MovieListContract.Model model;


    public MovieListPresenter() {
        model = new MovieListModel();
    }

    @Override
    public void getHot(String type, String sort) {

        Map<String, Object> par = getPublicPar();
        par.put("type", type);

        model.getHot(par)
                .compose(RxScheduler.Obs_io_main())
                .to(mView.bindAutoDispose())
                .subscribe(new MyObserver<BaseListBean<MovieBean>>(mView) {
                    @Override
                    public void success(@NonNull BaseListBean<MovieBean> baseBean) {
                        baseBean.handleData(MovieBean.class);
                        if (baseBean.getData() != null && baseBean.getData().size() > 0) {
                            mView.showHot(baseBean.getData());
                        }
                    }
                });

    }

    @Override
    public void getDayHot(int pageNumber, String type) {

        Map<String, Object> par = getPublicPar();
        par.put("type", type);
        par.put("page", pageNumber);
        par.put("size", Contents.PAGE_SIZE);


        model.getDayHot(par)
                .compose(RxScheduler.Obs_io_main())
                .to(mView.bindAutoDispose())
                .subscribe(new MyObserver<BaseListBean<MovieBean>>(mView) {
                    @Override
                    public void success(@NonNull BaseListBean<MovieBean> baseBean) {
                        baseBean.handleData(MovieBean.class);
                        if (mView != null) {
                            if (baseBean.getData() != null && baseBean.getData().size() > 0) {
                                mView.showDayHot(baseBean.getData());
                            }else{
                                mView.showNoMore();
                            }
                        }
                    }
                });
    }
}
